package logic

import (
	"class-exer/models/mysql"
	"context"
	"gorm.io/gorm"

	"class-exer/userrpc/internal/svc"
	"class-exer/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectLogic) Perfect(in *userrpc.PerfectRequest) (*userrpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line
	user := mysql.User{
		Model: gorm.Model{
			ID: uint(in.UserId),
		},
		Age:       in.Age,
		Address:   in.Address,
		HeadImage: in.HeadImage,
	}
	mysql.DB.Debug().Create(&user)
	return &userrpc.PerfectResponse{
		UserId: int64(user.ID),
	}, nil
}
